/*
 * @Author: tyz
 * @Date: 2021-06-25 09:59:16
 * @LastEditTime: 2021-06-25 10:14:52
 * @Description: 自定义队列事件
 * @FilePath: \nest_demo\src\queue\audio.processor.ts
 */
import { Process, Processor, OnQueueActive } from '@nestjs/bull';
import { Logger } from '@nestjs/common';
import { Job } from 'bull';


@Processor('audio')
export class AudioProcessor {
  private readonly logger = new Logger(AudioProcessor.name);

  @OnQueueActive()
  onActive(job: Job) {
    this.logger.debug(`Processing job ${job.id} of type ${job.name} with data ${job.data}...`)
  }

  /*
    * 对应controller文件中this.audioQueue.add()内部调用的'transcode'方法
    *
    * 'job'就是this.audioQueue.add()内部的file属性
  */
  @Process('transcode')
  handleTranscode(job: Job) {
    this.logger.debug('Start transcoding...');
    this.logger.debug(job.data);
    this.logger.debug('Transcoding completed');
  }
}
